package com.example.egweibo1.controller;

import com.example.egweibo1.base.response.Result;
import com.example.egweibo1.mapper.UserMapper;
import com.example.egweibo1.pojo.dto.UserAddParam;
import com.example.egweibo1.pojo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author tune_the last
 * @date 2025/11/13 - 17:25
 */
@RestController
@RequestMapping("/v1/user")
@Slf4j
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @PostMapping("/add")
    public Result addUser(@RequestBody UserAddParam userAddParam){
        log.debug("收到的数据:"+userAddParam);
        User user = new User();
        BeanUtils.copyProperties(userAddParam, user);
        user.setCreated(new Date());
        int i = userMapper.insertUser(user);
        if (i > 0){
            return Result.ok();
        }
        return Result.fail();
    }
}
